<html xmlns="http://www.w3.org/1999/xhtml" xmlns:c="http://java.sun.com/jstl/core"
      xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:t="http://myfaces.apache.org/tomahawk"
      xmlns:v="http://corejsf.com/validator">

    <f:view>
        <f:loadBundle var="text" basename="#{quotationForm.bundleName}"/>
        <script type="text/javascript" src="../operations/productAutoComplete.js"></script>
        <script type="text/javascript" src="../scripts/cssPopup.js"></script>
        <style type="text/css">
            #title {
                float: left;
            }
            #close {
                float: right;
            }
            #blanket {
                background-color:#111;
                opacity: 0.65;
                filter:alpha(opacity=65);
                position:absolute;
                z-index: 9001;
                top:0px;
                left:0px;
                width:100%;
            }
            #popUpDiv {
                position:absolute;
                background-color:#DAE0A5;
                border: #6C742D;
                width:300px;
                height:200px;
                z-index: 9002;
            }
            #pbody {
                padding: 5px;
            }
            #pmenu {
                padding: 5px;
                background-color:#B4C24B;
            }
            .inactiveTab {
                background-color: #D7E9F5;
                border-color:#74B3DC;
            }
            .inactiveTab input{
                background-color: #D7E9F5;
            }
            .inactiveTab input.button, button{
                background-color: #F7F7F7;
            }
            .activeTab {
                background-color: #ffffff;
                border-color:#74B3DC;
            }
            .activeTab input {
                background-color: #ffffff;
            }
        </style>
        <head>
            <title>#{text['quotationDetail.title']}</title>
            <meta name="heading" content="#{text['quotationDetail.heading']}"/>
            <meta name="menu" content="OperationMenu"/>
        </head>

        <div class="separator"></div>

        <h:form id="quotationForm">
            <h:inputHidden value="#{quotationForm.quotation.id}" id="id"/>

            <h:panelGrid columns="3">

                <h:panelGroup styleClass="buttonBar right">
                    <c:if test="#{!quotationForm.isView}">
                        <h:commandButton value="#{text['button.save']}" action="#{quotationForm.save}"
                                         id="save" styleClass="button"/>
                    </c:if>
                    <c:if test="${not empty quotationForm.quotation.id}">
                        <h:commandButton id="print" value="#{text['button.print']}"
                                         onclick="return printQuotation(#{quotationForm.quotation.id});"
                                         styleClass="button"/>
                        <c:if test="#{quotationForm.quotation.status == 'APROBADA' or quotationForm.quotation.status == 'REMITIDA'}">
                            <h:commandButton value="#{text['button.invoice']}" action="#{quotationForm.generateInvoice}"
                                             immediate="true" id="invoice" styleClass="button"/>
                        </c:if>
                        <c:if test="#{!quotationForm.isView}">
                            <h:commandButton value="#{text['button.cancel']}" action="#{quotationForm.cancel}"
                                             id="cancel" styleClass="button"/>
                            <a id="raisePopup" href="#" onclick="popup('popUpDiv')">
                                <img alt="Aprobar" src="../images/aprobar.bmp" style="padding: 2px;"/>
                            </a>
                        </c:if>
                    </c:if>
                    <h:commandButton value="#{text['button.close']}" action="cancel" immediate="true"
                                     id="close" styleClass="button"/>
                </h:panelGroup>
                <h:outputText/><h:outputText/>

                <h:panelGroup styleClass="info">
                    <c:choose>
                        <c:when test="${param.from == 'list' or empty quotationForm.quotation.id}">
                            <h:outputText value="#{text['quotationDetail.admin.message']}"/>
                        </c:when>
                        <c:otherwise><h:outputText value="#{text['quotationDetail.message']}"/></c:otherwise>
                    </c:choose>
                </h:panelGroup>
                <h:outputText/><h:outputText/>

                <h:panelGroup>
                    <div>
                        <div class="left">
                            <h:outputLabel styleClass="desc" for="_id" value="#{text['quotation.id']}"/>
                            <h:inputText styleClass="text medium" id="_id" value="#{quotationForm.quotation.id}" readonly="true"/>
                            <t:message for="_id" styleClass="fieldError"/>
                        </div>
                        <div>
                            <h:outputLabel styleClass="desc" for="transDate" value="#{text['quotation.transDate']}"/>
                            <h:inputText styleClass="text medium" id="transDate" value="#{quotationForm.quotation.transDate}" readonly="true">
                                <f:convertDateTime pattern="dd/MM/yyyy"/>
                            </h:inputText>
                            <t:message for="transDate" styleClass="fieldError"/>
                        </div>
                    </div>
                </h:panelGroup>

                <h:outputText/><h:outputText/>

                <h:outputLabel for="description" styleClass="desc" value="#{text['quotation.description']}"/>
                <t:message for="description" styleClass="fieldError"/>
                <h:inputText id="description" value="#{quotationForm.quotation.description}" styleClass="text large" readonly="#{quotationForm.isView}">
                    <!--v:commonsValidator client="true" type="required" arg="#{text['quotation.description']}"/-->
                </h:inputText>
                <h:outputText/><h:outputText/>

                <h:panelGroup>
                    <div>
                        <div class="left">
                            <h:selectOneMenu value="#{quotationForm.quotation.company}" id="company" required="true" styleClass="select" disabled="#{quotationForm.isView}"
                                             valueChangeListener="#{quotationForm.processCompanyChange}" onchange="this.form.submit();">
                                <f:selectItem itemLabel="Todas"/>
                                <t:selectItems value="#{quotationForm.companies}" var="company" itemLabel="#{company.description}" itemValue="#{company}"/>
                                <f:converter converterId="objconverter"/>
                            </h:selectOneMenu>
                            <t:message for="company" styleClass="fieldError"/>
                            <v:commonsValidator client="true" type="required" arg="#{text['quotation.company']}"/>
                            <t:htmlTag value="p"><h:outputLabel for="company" value="#{text['quotation.company']}"/></t:htmlTag>
                        </div>
                        <div>
                            <h:selectOneMenu value="#{quotationForm.quotation.contact}" id="contact" required="true" styleClass="select" disabled="#{quotationForm.isView}">
                                <f:selectItem itemLabel="Todos"/>
                                <t:selectItems value="#{quotationForm.contacts}" var="contact" itemLabel="#{contact.firstName} #{contact.lastName}" itemValue="#{contact}"/>
                                <f:converter converterId="objconverter"/>
                            </h:selectOneMenu>
                            <v:commonsValidator client="true" type="required" arg="#{text['quotation.contact']}"/>
                            <t:message for="contact" styleClass="fieldError"/>
                            <t:htmlTag value="p"><h:outputLabel for="contact" value="#{text['quotation.contact']}"/></t:htmlTag>
                        </div>
                    </div>
                </h:panelGroup>
                <h:outputText/><h:outputText/>

                <h:panelGroup>
                    <div>
                        <div class="left">
                            <h:selectOneMenu value="#{quotationForm.quotation.currency}" id="currency" required="true" styleClass="select" disabled="#{quotationForm.isView}"
                                             valueChangeListener="#{quotationForm.processCurrencyChange}" onchange="this.form.submit();">
                                <t:selectItems value="#{quotationForm.currencies}" var="currency" itemLabel="#{currency.description}" itemValue="#{currency}"/>
                                <f:converter converterId="objconverter"/>
                            </h:selectOneMenu>
                            <v:commonsValidator client="true" type="required" arg="#{text['quotation.currency']}"/>
                            <t:message for="currency" styleClass="fieldError"/>
                            <t:htmlTag value="p"><h:outputLabel for="currency" value="#{text['quotation.currency']}"/></t:htmlTag>
                        </div>
                        <div>
                            <h:selectOneMenu value="#{quotationForm.quotation.paymentMethod}" id="paymentMethod" required="true" styleClass="select" disabled="#{quotationForm.isView}">
                                <t:selectItems value="#{quotationForm.paymentMethods}" var="paymentMethod" itemLabel="#{paymentMethod.description}" itemValue="#{paymentMethod}"/>
                                <f:converter converterId="objconverter"/>
                            </h:selectOneMenu>
                            <v:commonsValidator client="true" type="required" arg="#{text['quotation.paymentMethod']}"/>
                            <t:message for="paymentMethod" styleClass="fieldError"/>
                            <t:htmlTag value="p"><h:outputLabel for="paymentMethod" value="#{text['quotation.paymentMethod']}"/></t:htmlTag>
                        </div>
                    </div>
                </h:panelGroup>
                <h:outputText/><h:outputText/>

                <h:panelGroup>
                    <div>
                        <div class="left">
                            <h:selectOneMenu value="#{quotationForm.quotation.deliveryTime}" id="deliveryTime" required="true" styleClass="select" disabled="#{quotationForm.isView}">
                                <t:selectItems value="#{quotationForm.deliveryTimes}" var="deliveryTime" itemLabel="#{deliveryTime.description}" itemValue="#{deliveryTime}"/>
                                <f:converter converterId="objconverter"/>
                            </h:selectOneMenu>
                            <v:commonsValidator client="true" type="required" arg="#{text['quotation.deliveryTime']}"/>
                            <t:message for="deliveryTime" styleClass="fieldError"/>
                            <t:htmlTag value="p"><h:outputLabel for="deliveryTime" value="#{text['quotation.deliveryTime']}"/></t:htmlTag>
                        </div>
                        <div>
                            <h:selectOneMenu value="#{quotationForm.quotation.guarantee}" id="guarantee" required="true" styleClass="select" disabled="#{quotationForm.isView}">
                                <t:selectItems value="#{quotationForm.guarantees}" var="guarantee" itemLabel="#{guarantee.description}" itemValue="#{guarantee}"/>
                                <f:converter converterId="objconverter"/>
                            </h:selectOneMenu>
                            <v:commonsValidator client="true" type="required" arg="#{text['quotation.guarantee']}"/>
                            <t:message for="guarantee" styleClass="fieldError"/>
                            <t:htmlTag value="p"><h:outputLabel for="guarantee" value="#{text['quotation.guarantee']}"/></t:htmlTag>
                        </div>
                    </div>
                </h:panelGroup>
                <h:outputText/><h:outputText/>

                <h:panelGroup>
                    <div>
                        <div class="left">
                            <h:outputLabel styleClass="desc" for="exchangeRate" value="#{text['quotation.exchangeRate']}"/>
                            <h:inputText styleClass="text medium" id="exchangeRate" value="#{quotationForm.quotation.exchangeRate}" required="true" disabled="#{quotationForm.isView}"/>
                            <t:message for="exchangeRate" styleClass="fieldError"/>
                            <t:htmlTag value="p"><h:outputLabel for="exchangeRate" value="#{text['quotation.exchangeRate']}" rendered="#{quotationForm.quotation.exchangeCurrency != null}"/></t:htmlTag>
                        </div>
                        <div class="left">
                            <h:outputLabel styleClass="desc" for="totalCost" value="#{text['quotation.totalCost']}"/>
                            <h:inputText styleClass="text medium" id="totalCost" value="#{quotationForm.quotation.totalCost}" disabled="true">
                                <f:convertNumber type="number" pattern="#,##0.00;(#,##0.00)"/>
                            </h:inputText>
                            <t:htmlTag value="p"><h:outputLabel for="totalCost" value="#{quotationForm.quotation.currency}" rendered="#{quotationForm.quotation.currency != null}"/></t:htmlTag>
                        </div>
                        <div class="left">
                            <h:outputLabel styleClass="desc" for="equivalentAmount" value="#{text['quotation.equivalentAmount']}"/>
                            <h:inputText styleClass="text medium" id="equivalentAmount" value="#{quotationForm.quotation.equivalentAmount}" disabled="true">
                                <f:convertNumber type="number" pattern="#,##0.00;(#,##0.00)"/>
                            </h:inputText>
                            <t:htmlTag value="p"><h:outputLabel for="equivalentAmount" value="#{quotationForm.quotation.exchangeCurrency}" rendered="#{quotationForm.quotation.exchangeCurrency != null}"/></t:htmlTag>
                        </div>
                    </div>
                </h:panelGroup>
                <h:outputText/><h:outputText/>                

                <t:panelTabbedPane activeTabStyleClass="activeTab"
                                   inactiveTabStyleClass="inactiveTab"
                                   disabledTabStyleClass="inactiveTab"
                                   activeSubStyleClass="activeTab"
                                   inactiveSubStyleClass="inactiveTab"
                                   tabContentStyleClass="activeTab"
                                   rendered="#{quotationForm.quotation.status == 'SOLICITADA'}">
                    <t:panelTab id="products" label="Productos" title="Productos">
                        <h:panelGroup>
                            <t:htmlTag id="addProductDiv" value="div" styleClass="group">
                                <t:htmlTag id="productDescriptionDiv" value="div" styleClass="left">
                                    <h:outputLabel styleClass="desc" value="#{text['quotation.product.description']}"/>
                                    <input type="text" id="autocomplete" name="autocomplete_parameter" class="text large"/>
                                </t:htmlTag>
                                <div id="autocomplete_choices" class="autocomplete"></div>
                                <h:inputHidden id="productDescription" value="#{quotationForm.productDescription}"/>
                                <h:inputHidden id="productPrice" value="#{quotationForm.productPrice}"/>
                                <h:inputHidden id="productId" value="#{quotationForm.productId}"/>
                                <h:inputHidden id="productMeasure" value=""/>
                                <t:htmlTag id="productQuantityDiv" value="div" styleClass="rigth"><br/>
                                    <h:outputLabel styleClass="desc" for="quantity" value="#{text['quotation.product.quantity']}"/>
                                    <h:inputText styleClass="text medium" id="quantity" value="#{quotationForm.quantity}" disabled="#{quotationForm.isView}"/>
                                    <t:message for="quantity" styleClass="fieldError"/>
                                </t:htmlTag>
                                <br/>
                                <!--t:htmlTag id="buttonAgregarDiv" value="div">
                                    <h:commandButton value="Agregar" style="visibility: hidden;"/>
                                </t:htmlTag-->
                                <t:htmlTag id="productMeasureDiv" value="div" styleClass="left">
                                    <h:outputLabel styleClass="desc" for="measure" value="#{text['product.measure']}"/>
                                    <h:inputText styleClass="text medium" id="measure" value="#{quotationForm.myMeasure}" disabled="#{quotationForm.isView}"/>
                                    <t:message for="measure" styleClass="fieldError"/>
                                </t:htmlTag>
                                <t:htmlTag id="productUnitMeasureDiv" value="div">
                                    <h:outputLabel styleClass="desc" for="productUnitMeasure" value="#{text['product.unitMeasure']}"/>
                                    <h:inputText styleClass="text medium" id="productUnitMeasure" value="" disabled="true"/>
                                    <t:message for="productUnitMeasure" styleClass="fieldError"/>
                                </t:htmlTag>
                                <t:htmlTag value="div">
                                    <t:commandButton id="addProduct" actionListener="#{quotationForm.addProduct}" value="Agregar" disabled="#{quotationForm.isView}"/>
                                </t:htmlTag>
                            </t:htmlTag>
                        </h:panelGroup>
                    </t:panelTab>
                    <t:panelTab id="others" label="Otros" title="Otros">
                        <h:panelGroup>
                            <t:htmlTag value="div" styleClass="group">
                                <h:outputLabel styleClass="desc" for="otherProductDescription" value="#{text['quotation.anotherProduct.description']}"/>
                                <h:inputText styleClass="text large" id="otherProductDescription" value="#{quotationForm.otherProductDescription}" disabled="#{quotationForm.isView}"/>
                                <t:htmlTag value="p"><h:outputLabel for="otherProductDescription" value="#{text['quotation.anotherProduct.description']}"/></t:htmlTag>
                                <t:htmlTag value="div"  styleClass="left">
                                    <h:outputLabel styleClass="desc" for="otherProductPrice" value="#{text['quotation.product.price']}"/>
                                    <h:inputText styleClass="text medium" id="otherProductPrice" value="#{quotationForm.otherProductPrice}" disabled="#{quotationForm.isView}"/>
                                    <t:message for="otherProductPrice" styleClass="fieldError"/>
                                    <t:htmlTag value="p"><h:outputLabel for="otherProductPrice" value="#{quotationForm.quotation.currency}" rendered="#{quotationForm.quotation.currency != null}"/></t:htmlTag>
                                </t:htmlTag>
                                <t:htmlTag value="div">
                                    <h:outputLabel styleClass="desc" for="otherProductQuantity" value="#{text['quotation.product.quantity']}"/>
                                    <h:inputText styleClass="text medium" id="otherProductQuantity" value="#{quotationForm.otherProductQuantity}" disabled="#{quotationForm.isView}"/>
                                    <t:message for="otherProductQuantity" styleClass="fieldError"/>
                                </t:htmlTag>
                                <t:htmlTag value="div">
                                    <t:commandButton id="addAnotherProduct" actionListener="#{quotationForm.addAnotherProduct}" value="Agregar" styleClass="button" disabled="#{quotationForm.isView}"/>
                                </t:htmlTag>
                            </t:htmlTag>
                        </h:panelGroup>
                    </t:panelTab>
                </t:panelTabbedPane>

                <h:outputText/><h:outputText/>
                <t:saveState id="save1" value="#{quotationForm.contact}" />
                <t:saveState id="save2" value="#{quotationForm.contacts}" />
                <t:saveState id="save3" value="#{quotationForm.quotation}" />
                <t:saveState id="save4" value="#{quotationForm.deletes}" />
                <t:saveState id="save5" value="#{quotationForm.company}" />
                <t:saveState id="save6" value="#{quotationForm.companies}" />
                <t:dataTable value="#{quotationForm.quotation.details}" var="detail" width="100%" id="_products"
                             styleClass="scrollerTable table" rowIndexVar="indx"
                             preserveDataModel="true">
                    <t:column width="40%">
                        <f:facet name="header">
                            <t:outputText value="#{text['quotation.product']}"/>
                        </f:facet>
                        <t:outputText value="#{detail.product.description}" rendered="#{detail.product != null}"/>
                        <t:outputText value="#{detail.itemDescription}" rendered="#{detail.product == null}"/>
                    </t:column>
                    <t:column width="10%">
                        <f:facet name="header">
                            <t:outputText value="#{text['quotation.product.price']}"/>
                        </f:facet>
                        <t:inputText id="_price" styleClass="number small" value="#{detail.price}" disabled="#{quotationForm.isView}" readonly="#{detail.product == null}"
                                     onchange="return calc(#{detail.product.price},#{detail.quantity}, #{detail.measure}, this.value,#{detail.product.minPrice},#{detail.product.maxPrice}, #{indx});">
                            <f:convertNumber type="number" pattern="#,##0.00;(#,##0.00)"/>
                        </t:inputText>
                    </t:column>
                    <t:column width="10%">
                        <f:facet name="header">
                            <t:outputText id="measure" value="#{text['quotation.product.measure']}"/>
                        </f:facet>
                        <t:outputText value="#{detail.measure}" style="text-align: right;"/>
                    </t:column>
                    <t:column width="10%">
                        <f:facet name="header">
                            <t:outputText value="#{text['quotation.product.unitMeasure']}"/>
                        </f:facet>
                        <t:outputText id="unitMeasure" value="#{detail.product.unitMeasure}" rendered="#{detail.product != null}" style="text-align: right;"/>
                    </t:column>
                    <t:column width="10%">
                        <f:facet name="header">
                            <t:outputText id="quantity_#{indx}" value="#{text['quotation.product.quantity']}"/>
                        </f:facet>
                        <t:outputText value="#{detail.quantity}" style="text-align: right;"/>
                        <f:facet name="footer">
                            <h:panelGrid>
                                <h:outputText value="Sub Total:"/>
                                <h:outputText value="Impuesto:"/>
                                <h:outputText value="Total:"/>
                            </h:panelGrid>
                        </f:facet>
                    </t:column>
                    <t:column width="10%">
                        <f:facet name="header">
                            <t:outputText value="#{text['quotation.product.total']}"/>
                        </f:facet>
                        <t:inputText id="_subTotal" value="#{detail.subTotal}" readonly="true" styleClass="number small">
                            <f:convertNumber type="number" pattern="#,##0.00;(#,##0.00)"/>
                        </t:inputText>
                        <f:facet name="footer">
                            <h:panelGrid>
                                <t:inputText id="_pSubTotal" value="#{quotationForm.quotation.subtotal}" styleClass="number small" readonly="true">
                                    <f:convertNumber type="number" pattern="#,##0.00;(#,##0.00)"/>
                                </t:inputText>
                                <t:inputText id="_pTax" value="#{quotationForm.quotation.tax}" styleClass="number small" readonly="true">
                                    <f:convertNumber type="number" pattern="#,##0.00;(#,##0.00)"/>
                                </t:inputText>
                                <t:inputText id="_pTotal" value="#{quotationForm.quotation.totalCost}" styleClass="number small" readonly="true">
                                    <f:convertNumber type="number" pattern="#,##0.00;(#,##0.00)"/>
                                </t:inputText>
                                <t:htmlTag value="p"><h:outputLabel for="_pTotal" value="#{quotationForm.quotation.currency}" rendered="#{quotationForm.quotation.currency != null}"/></t:htmlTag>
                            </h:panelGrid>
                        </f:facet>
                    </t:column>
                    <t:column width="10%">
                        <f:facet name="header">
                        </f:facet>
                        <h:commandLink actionListener="#{quotationForm.deleteProduct}" value="Borrar" disabled="#{quotationForm.isView}">
                            <f:param id="detailId" name="detailId" value="#{indx}"/>
                        </h:commandLink>
                    </t:column>
                </t:dataTable>                

                <h:outputLabel for="notes" styleClass="desc" value="#{text['quotation.notes']}"/>
                <h:inputText value="#{quotationForm.quotation.notes}" id="notes" styleClass="text large" readonly="#{quotationForm.isView}"/>

                <h:outputText/><h:outputText/>
                <h:panelGroup>
                    <t:htmlTag value="div" styleClass="group">
                        <t:htmlTag value="div" styleClass="left">
                            <h:inputText id="createdBy" disabled="true"
                                         value="#{quotationForm.quotation.createdBy.fullName}"/>
                            <t:htmlTag value="p"><h:outputLabel for="createdBy" value="#{text['quotation.createdBy']}"/></t:htmlTag>
                        </t:htmlTag>
                        <t:htmlTag value="div">
                            <h:inputText id="createdOn" disabled="true"
                                         value="#{quotationForm.quotation.createdOn}"/>
                            <t:htmlTag value="p"><h:outputLabel for="createdOn" value="#{text['quotation.createdOn']}"/></t:htmlTag>
                        </t:htmlTag>
                        <t:htmlTag value="div" styleClass="left">
                            <h:inputText id="modifiedBy" disabled="true"
                                         value="#{quotationForm.quotation.modifiedBy.fullName}"/>
                            <t:htmlTag value="p"><h:outputLabel for="modifiedBy" value="#{text['quotation.modifiedBy']}"/></t:htmlTag>
                        </t:htmlTag>
                        <t:htmlTag value="div">
                            <h:inputText id="modifiedOn" disabled="true"
                                         value="#{quotationForm.quotation.modifiedOn}"/>
                            <t:htmlTag value="p"><h:outputLabel for="modifiedOn" value="#{text['quotation.modifiedOn']}"/></t:htmlTag>
                        </t:htmlTag>
                    </t:htmlTag>
                </h:panelGroup>
            </h:panelGrid>            
            <div id="blanket" style="display:none;"></div>            
            <div id="popUpDiv" style="display:none;">
                <div id="pmenu">
                    <h:outputText value="Aprobar Cotizacion"/>
                    <a id="close" href="#" onclick="popup('popUpDiv')">Cerrar</a>
                </div>
                <br/>
                <br/>
                <div id="pbody">
                    <h:panelGrid columns="2">
                        <h:outputText value="Asignar a: "/>
                        <h:selectOneMenu value="#{quotationForm.responsible}" id="responsible" styleClass="select">
                            <t:selectItems value="#{quotationForm.responsibles}" var="responsible" itemLabel="#{responsible.firstName} #{responsible.lastName}" itemValue="#{responsible}"/>
                            <f:converter converterId="objconverter"/>
                        </h:selectOneMenu>
                    </h:panelGrid>
                    <br/>
                    <center>
                        <h:commandButton value="#{text['button.approve']}" action="#{quotationForm.approve}"
                                         id="pop_approve" styleClass="button"/>
                    </center>
                </div>
            </div>
        </h:form>

        <script type="text/javascript">
                                             Form.focusFirstElement($('quotationForm'));
                                             highlightFormElements();
        </script>
        <script type="text/javascript">
            function printReport(report, id) {
                window.open('/birt-viewer/run?__report=' + report + '&amp;p_cotizacion=' + id + '__format=html', 'SuArte', 'height=700,width=800,status=yes,toolbar=no,menubar=yes,location=no,resizable=yes');
                return false;
            }
            function calc(price, quantity, measure, newPrice, minPrice, maxPrice, indx) {
                if (minPrice > newPrice) {
                    alert('El precio minimo es ' + minPrice);
                    $('quotationForm:_products:' + indx + ':_price').value = formatNumber(parseFloat(price));
                    $('quotationForm:_products:' + indx + ':_subTotal').value = formatNumber((parseFloat(price) * parseFloat(quantity) * parseFloat(measure)).toFixed(2), 2);
                    updateTotal();
                    $('quotationForm:_products:' + indx + ':_price').focus();
                    return false;
                }
                if (newPrice > maxPrice) {
                    alert('El precio maximo es ' + maxPrice);
                    $('quotationForm:_products:' + indx + ':_price').value = formatNumber(parseFloat(price));
                    $('quotationForm:_products:' + indx + ':_subTotal').value = formatNumber((parseFloat(price) * parseFloat(quantity) * parseFloat(measure)).toFixed(2), 2);
                    updateTotal();
                    $('quotationForm:_products:' + indx + ':_price').focus();
                    return false;
                }
                $('quotationForm:_products:' + indx + ':_subTotal').value = formatNumber((parseFloat(newPrice) * parseFloat(quantity) * parseFloat(measure)).toFixed(2), 2);
                $('quotationForm:_products:' + indx + ':_price').value = formatNumber(parseFloat(newPrice), 2);
                updateTotal();
                return true;
            }
            function updateTotal() {
                var tableRows = $('quotationForm:_products').rows;
                var subTotal = 0;
                var total = 0;
                var tax = 0;
                var val = 0;
                for (var i = 1; tableRows.length - 1 > i; i++) {
                    val = tableRows[i].cells[5].firstChild.value;
                    val = parseFloat(val.replace(/\,/g, ''));
                    subTotal = subTotal + val;
                }
                tax = subTotal * 0.15;
                total = subTotal + tax;
                $('quotationForm:_products:_pSubTotal').value = formatNumber(subTotal, 2);
                $('quotationForm:_products:_pTax').value = formatNumber(tax.toFixed(2), 2);
                $('quotationForm:_products:_pTotal').value = formatNumber(total, 2);
            }

            function printQuotation(id) {
                window.open('/suarte-web/documento.pdf?id=' + id + '&amp;type=quotation', 'Suarte', 'height=800,width=700,status=yes,toolbar=no,menubar=no,location=no,resizable=yes');
                return false;
            }
        </script>
    </f:view>
</html>